package com.sporadic.desk.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sporadic.desk.dao.UserDao;
import com.sporadic.desk.pojo.User;
import com.sporadic.desk.service.UserService;
import dto.UserDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @program: sporadic
 * @description:
 * @author: LHD   QQ:1727865856
 * @create: 2019-11-26 11:50
 **/
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {
    @Override
    public List<UserDTO> selAll(String phone) {
        List<User> list=null;
        try {
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.like(!(phone == null), "user_phone", phone);
            list = super.list(queryWrapper);
        }catch (Exception e){
            throw new RuntimeException("异常！");
        }
        List<UserDTO> userDTOList=new ArrayList<>();
        list.forEach(user->{
            UserDTO userDTO=new UserDTO();
            BeanUtils.copyProperties(user,userDTO);
            userDTOList.add(userDTO);
        });
        return userDTOList;
    }
}
